from typing import Callable, Dict, Any
from dataclasses import dataclass

# 传统命令模式的函数式改造
@dataclass(frozen=True)
class Command:
    execute: Callable[[], Any]
    undo: Callable[[], Any]

def create_counter_commands(initial_value: int = 0):
    """创建计数器相关的命令"""
    counter = {'value': initial_value}

    def increment():
        counter['value'] += 1
        return counter['value']

    def decrement():
        counter['value'] -= 1
        return counter['value']

    return {
        'increment': Command(increment, decrement),
        'decrement': Command(decrement, increment)
    }

if __name__ == '__main__':
    counter_commands = create_counter_commands()
    print(counter_commands['increment'].execute())